import React from 'react';
import { inject, observer} from 'mobx-react';
import {WeaTableNew} from 'comsMobx';
import * as mobx from 'mobx';
import { Button } from 'antd';
import {WeaTop,WeaTab,WeaLeftRightLayout,WeaRightMenu,WeaPopoverHrm,WeaTools,WeaErrorPage,WeaLocaleProvider
        ,WeaDialog,WeaAuth} from 'ecCom';

const { toJS } = mobx;
const WeaTable = WeaTableNew.WeaTable;
const getLabel = WeaLocaleProvider.getLabel;

@inject('wfFreeFlowTemplateStore')
@observer
class AddShareFreeTemplate extends React.Component {
    constructor(props) {
		super(props);
    }
    doInit(props){
        const { wfFreeFlowTemplateStore } = props;
        const { searchList , getAddTemplateBaseData} = wfFreeFlowTemplateStore;
        
    }
    componentDidMount() {
        this.doInit(this.props);
    }
    componentWillReceiveProps(nextProps) {
    }
    render() {
        const { wfFreeFlowTemplateStore } = this.props;
        const { addShareModalShow , setAddShareModalShow , shareRangeConfigs , saveAddedShare} = wfFreeFlowTemplateStore;
        
        const conditions = [toJS(shareRangeConfigs).linkage,toJS(shareRangeConfigs).typeConfig];
        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@a3mog3`}
                visible={addShareModalShow}
                title={getLabel(18645,'添加共享')}
                icon="icon-coms-workflow"
                iconBgcolor='#0079DE'
                maskClosable={false}
                buttons={this.getModalBtns()}
                onCancel={() => setAddShareModalShow(false)}
                style={{width: "600px",height:'300px'}}
                moreBtn={{datas:this.getRightMenu()}}
                hasScroll
            >
                <div className="wf-free-flowset-addShareModal">
                    <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@17sswx`} 
                        collectParams={{favname:getLabel(18645,'添加共享'), favouritetype:2}}
                        datas={this.getRightMenu()}>
                        <WeaAuth ecId={`${this && this.props && this.props.ecId || ''}_WeaAuth@0uci44`}
                            ref={(ref)=>{wfFreeFlowTemplateStore.addShareRef = ref}}
                            type='form'
                            conditions={toJS(conditions)}
                            onOk={data => saveAddedShare(data) }
                        />
                    </WeaRightMenu>
                </div>
            </WeaDialog>
        );
        /*
        if(addShareModalShow){
            return (
                <WeaAuth
                    visible={addShareModalShow}
                    conditions={conditions}
                    title={'添加共享'}
                    onOk={v => {
                        console.log('onOk datas: ', v);
                        setAddShareModalShow(false);
                    }}
                    onCancel={() => {
                        setAddShareModalShow(false);
                    }}
                />
            )
        }else{
            return (
            <div></div>
            )
        }
        */
    }
    addSave(goDetail = false){
        const { wfFreeFlowTemplateStore } = this.props;
        const { addShareRef } = wfFreeFlowTemplateStore;
        addShareRef.onOk();
    } 
    getModalBtns(){
        let btns = [];
        btns.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@wc2sli@save`} type="primary" onClick={()=>{this.addSave()}}>{getLabel(86,'保存')}</Button>);
        return btns;
    }
    getRightMenu(){
        let rtMenus = [];
        rtMenus.push({
            key: "save",
    		icon: <i className="icon-coms-Preservation"/>,
            content:getLabel(86,'保存'),
            onClick: key =>{ this.addSave()}
        });
    	return rtMenus;
    }
}

export default WeaTools.tryCatch(React, 
    props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@0s6p8i`} msg={ props.error ? props.error : getLabel(383324,' 对不起，该页面异常，请联系管理员 ')+'！'} />,
    {error: ""}
)(AddShareFreeTemplate);